package com.guoguo.dao;

import java.io.Serializable;
import java.util.List;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.guoguo.annotations.Transactional;
import com.guoguo.bean.Employee;

@Named
@SessionScoped
public class EmployeeManager implements Serializable,Manager{

	private static final long serialVersionUID = 1816958998418728137L;

	@Inject
	private EntityManager entityManager;
	
	 public List<Employee> getEmployees(){
		 TypedQuery<Employee> q = entityManager.createQuery("select u from Employee u",Employee.class);
		 return q.getResultList();
	}
	 
	 public Employee find(int id){
		 return entityManager.find(Employee.class, id);
	 }
	 
	 @Transactional
	 public void merge(Employee e){
		 entityManager.merge(e);
	 }
	 
	 public EntityManager getEntityManager() {
			return this.entityManager;
		}
}
